#include "../HDCTitleWidget.h"
#include "../../include/HGlobalVariable.h"
#include "../../include/StdAfx.h"

HDCTitleWidget::HDCTitleWidget(QWidget *parent)
    :QWidget(parent)
{
    m_bPressed = false;
    m_posPressed = QPoint(0,0);
    initUI();
}

HDCTitleWidget::~HDCTitleWidget()
{

}

void HDCTitleWidget::paintEvent(QPaintEvent *event)
{
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    QWidget::paintEvent(event);
}

void HDCTitleWidget::mousePressEvent(QMouseEvent *event)
{
    m_bPressed = true;
    m_posPressed = event->pos();
    QWidget::mousePressEvent(event);
}

void HDCTitleWidget::mouseMoveEvent(QMouseEvent *event)
{
    if(m_bPressed)
    {
        int dx = event->pos().x() - m_posPressed.x();
        int dy = event->pos().y() - m_posPressed.y();
        emit sigMoveDistance(dx,dy);
    }
    QWidget::mouseMoveEvent(event);
}

void HDCTitleWidget::mouseReleaseEvent(QMouseEvent *event)
{
    m_bPressed = false;
    QWidget::mouseReleaseEvent(event);
}

void HDCTitleWidget::initUI()
{
    m_phblMain = new QHBoxLayout();
    m_phblMain->setContentsMargins(20,0,8,0);
    m_phblMain->setSpacing(0);

    m_phblButtonArea = new QHBoxLayout();
    m_phblButtonArea->setSpacing(0);
    m_phblButtonArea->setContentsMargins(0,0,0,0);

    m_pvblButtonArea = new QVBoxLayout();
    m_pvblButtonArea->setSpacing(0);
    m_pvblButtonArea->setContentsMargins(0,0,0,0);

    m_ppbMin = new QPushButton();
    m_ppbMin->setObjectName("login_btn_min");
    m_ppbMin->setFixedSize(NLITTLEICONSIZE,NLITTLEICONSIZE);

    m_ppbClose = new QPushButton();
    m_ppbClose->setObjectName("lgoin_btn_close");
    m_ppbClose->setFixedSize(NLITTLEICONSIZE,NLITTLEICONSIZE);

    m_plblLogo = new QLabel();
    QPixmap pixmapLogo(g_strAppPath + g_strImageRelationPath + "HIDI_TITLE_LOGO.png");
    m_plblLogo->setFixedSize(pixmapLogo.size());
    m_plblLogo->setPixmap(pixmapLogo);

    m_phblButtonArea->addWidget(m_ppbMin);
    m_phblButtonArea->addWidget(m_ppbClose);

    m_pvblButtonArea->addLayout(m_phblButtonArea,1);
    m_pvblButtonArea->addStretch(10);

    m_phblMain->addWidget(m_plblLogo,1);
    m_phblMain->addStretch(100);
    m_phblMain->addLayout(m_pvblButtonArea);

    this->setLayout(m_phblMain);
    this->setObjectName("dcTitleWidget");

    connect(m_ppbMin,SIGNAL(clicked()),this,SIGNAL(sigMinButtonClicked()));
    connect(m_ppbClose,SIGNAL(clicked()),this,SIGNAL(sigCloseButtonclicked()));

}

